{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 高德API功能调用\n",
    "\n",
    "Web服务API简介 \n",
    "高德Web服务API向开发者提供HTTP接口，开发者可通过这些接口使用各类型的地理数据服务，返回结果支持JSON和XML格式。\n",
    "\n",
    "Web服务API对所有用户开放。使用本组服务之前，需要申请应用Key。不同类型用户可获取不同的数据访问能力。\n",
    "\n",
    "高德官方文档:https://lbs.amap.com/api/webservice/summary\n",
    "\n",
    "* 调用功能：\n",
    "* 地理/逆地理编码\n",
    "* 路径规划\n",
    "* 行政区域查询\n",
    "* 搜索POI\n",
    "* IP定位\n",
    "* 批量请求接口\n",
    "* 静态地图\n",
    "* 坐标转换\n",
    "* 天气查询\n",
    "* 输入提示\n",
    "* 交通态势"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 准备工作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "# coding-utf-8\n",
    "\n",
    "import requests\n",
    "import json\n",
    "import pandas as pd\n",
    "my_key = \"12f80238641864b66003f76e69819ee4\"  #导入需要的模块和key值"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 地理编码和逆编码\n",
    "* 产品介绍:\n",
    "* 地理编码/逆地理编码 API 是通过 HTTP/HTTPS 协议访问远程服务的接口，提供结构化地址与经纬度之间的相互转化的能力。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 地理编码\n",
    "> * 1、结构化地址的定义： 首先，地址肯定是一串字符，内含国家、省份、城市、区县、城镇、乡村、街道、门牌号码、屋邨、大厦等建筑物名称。按照由大区域名称到小区域名称组合在一起的字符。一个有效的地址应该是独一无二的。注意：针对大陆、港、澳地区的地理编码转换时可以将国家信息选择性的忽略，但省、市、城镇等级别的地址构成是不能忽略的。暂时不支持返回台湾省的详细地址信息。    \n",
    "> * 2、url:https://restapi.amap.com/v3/geocode/geo?parameters      \n",
    "> * 3、requests.get()       \n",
    "> * 4、参数：   \n",
    "\n",
    ">> * A.必选：key（高德API秘钥），address(结构化地址)  \n",
    ">> * B.可选：\n",
    "\n",
    "**思考场景**\n",
    "* 城市建设辅助测绘信息"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " **函数**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "def geo(key,address,city=None,batch=None,sig=None,output=None,callback=None)->str:\n",
    "    \"\"\"获取高德API的地理编码\n",
    "    注释：key是指高德API的秘钥，请先去注册\n",
    "          填入address地理位置获得精确经纬度\n",
    "    \"\"\"\n",
    "    url = \"https://restapi.amap.com/v3/geocode/geo?parameters\"\n",
    "    params = {\n",
    "        \"key\":key,\n",
    "        \"address\":address,\n",
    "        \"city\":city,\n",
    "        \"batch\":batch,\n",
    "        \"sig\":sig,\n",
    "        \"output\":output,\n",
    "        \"callback\":callback\n",
    "        \n",
    "    }\n",
    "    #pa一定要放在前面\n",
    "    response = requests.get(url,params=params)\n",
    "    results = response.json()['geocodes'][0]['location']\n",
    "    # 返回值\n",
    "    return results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'113.679287,23.632575'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "geo(my_key,\"广东省广州市从化区中山大学南方学院\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 逆地理编码\n",
    "> * 2、url:https://restapi.amap.com/v3/geocode/regeo?parameters  \n",
    "> * 3、requests.get()       \n",
    "> * 4、参数：   \n",
    "\n",
    ">> * A.必选：key（高德API秘钥），location(经纬度坐标)  \n",
    ">> * B.可选：poitype radius\n",
    "\n",
    "**思考场景**\n",
    "* 城市建设辅助测绘信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "def regeo(key,location,poitype=None,radius=None,extensions=None,roadlevel=None,batch=None,output=None,callback=None,sig=None,homeorcorp=None)->str:\n",
    "    \"\"\"获取高德API的逆地理编码\n",
    "    注释：key是指高德API的秘钥，请先去注册\n",
    "          填入loacation经纬度获得地理位置\n",
    "    \"\"\"\n",
    "    url = \"https://restapi.amap.com/v3/geocode/regeo?parameters\"\n",
    "    params = {\n",
    "        \"key\":key,\n",
    "        \"location\":location,\n",
    "        \"poitype\":poitype,\n",
    "        \"radius\":radius,\n",
    "        \"extensions\":extensions,\n",
    "        \"roadlevel\":roadlevel,\n",
    "        \"batch\":batch,\n",
    "        \"output\":output,\n",
    "        \"callback\":callback,\n",
    "        \"sig\":sig,\n",
    "        \"homeorcorp\":homeorcorp\n",
    "        \n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    results = response.json()\n",
    "    # 返回值\n",
    "    return results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'regeocode': {'addressComponent': {'city': '广州市',\n",
       "   'province': '广东省',\n",
       "   'adcode': '440117',\n",
       "   'district': '从化区',\n",
       "   'towncode': '440117103000',\n",
       "   'streetNumber': {'number': '7号',\n",
       "    'location': '113.678600,23.633329',\n",
       "    'direction': '西北',\n",
       "    'distance': '109.203',\n",
       "    'street': '博学路'},\n",
       "   'country': '中国',\n",
       "   'township': '温泉镇',\n",
       "   'businessAreas': [[]],\n",
       "   'building': {'name': [], 'type': []},\n",
       "   'neighborhood': {'name': [], 'type': []},\n",
       "   'citycode': '020'},\n",
       "  'formatted_address': '广东省广州市从化区温泉镇中山大学南方学院'},\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000'}"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "regeo(my_key,'113.679287,23.632575')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 路径规划\n",
    "\n",
    "> 路径规划API是一套以HTTP形式提供的步行、公交、驾车查询及行驶距离计算接口，返回JSON 或 XML格式的查询数据，用于实现路径规划功能的开发。 \n",
    "\n",
    "\n",
    "**思考场景**\n",
    "* 导航地图\n",
    "* 用户输入目的地和出发点，返回最短路径"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 步行路径\n",
    "> url: https://restapi.amap.com/v3/direction/walking?parameters\n",
    "* 参数：\n",
    "\n",
    "* 必选:key,origin，destination(规则:（经度，纬度）经纬度小数点不超过6位)\n",
    "\n",
    "* 可选:sig"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'113.679287,23.632575'"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#获取纬度\n",
    "geo(my_key,\"广东省广州市从化区中山大学南方学院\",None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'113.678652,23.628412'"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "geo(my_key,\"广东省广州市从化区保利桃花源\",None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "def walking(key,origin,destination,output=None,callback=None,sig=None)->str:\n",
    "    \"\"\"获取高德API的地理编码\n",
    "    注释：key是指高德API的秘钥，请先去注册\n",
    "          填入origin起点经纬度\n",
    "          destinaton终点经纬度\n",
    "    \"\"\"\n",
    "    url = \"https://restapi.amap.com/v3/direction/walking?parameters\"\n",
    "    params = {\n",
    "        \"key\":key,\n",
    "        \"origin\":origin,\n",
    "        \"destination\":destination,\n",
    "        \"output\":output,\n",
    "        \"sig\":sig,\n",
    "        \"output\":output,\n",
    "        \"callback\":callback\n",
    "        \n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    # 返回值\n",
    "    return pd.json_normalize(response.json()['route']['paths'][0]['steps'])#列表形式获取信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instruction</th>\n",
       "      <th>orientation</th>\n",
       "      <th>road</th>\n",
       "      <th>distance</th>\n",
       "      <th>duration</th>\n",
       "      <th>polyline</th>\n",
       "      <th>action</th>\n",
       "      <th>assistant_action</th>\n",
       "      <th>walk_type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>向东步行101米右转</td>\n",
       "      <td>东</td>\n",
       "      <td>[]</td>\n",
       "      <td>101</td>\n",
       "      <td>81</td>\n",
       "      <td>113.679592,23.632491;113.680586,23.632522</td>\n",
       "      <td>右转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>向南步行199米向右前方行走</td>\n",
       "      <td>南</td>\n",
       "      <td>[]</td>\n",
       "      <td>199</td>\n",
       "      <td>159</td>\n",
       "      <td>113.680586,23.632522;113.680638,23.63214;113.6...</td>\n",
       "      <td>向右前方行走</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>向西步行159米左转</td>\n",
       "      <td>西</td>\n",
       "      <td>[]</td>\n",
       "      <td>159</td>\n",
       "      <td>127</td>\n",
       "      <td>113.680204,23.630838;113.680035,23.630773;113....</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>向南步行237米左转</td>\n",
       "      <td>南</td>\n",
       "      <td>[]</td>\n",
       "      <td>237</td>\n",
       "      <td>190</td>\n",
       "      <td>113.678711,23.63036;113.678711,23.62934;113.67...</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>向东步行35米到达目的地</td>\n",
       "      <td>东</td>\n",
       "      <td>[]</td>\n",
       "      <td>35</td>\n",
       "      <td>28</td>\n",
       "      <td>113.678273,23.628368;113.678572,23.628338;113....</td>\n",
       "      <td>[]</td>\n",
       "      <td>到达目的地</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      instruction orientation road distance duration  \\\n",
       "0      向东步行101米右转           东   []      101       81   \n",
       "1  向南步行199米向右前方行走           南   []      199      159   \n",
       "2      向西步行159米左转           西   []      159      127   \n",
       "3      向南步行237米左转           南   []      237      190   \n",
       "4    向东步行35米到达目的地           东   []       35       28   \n",
       "\n",
       "                                            polyline  action assistant_action  \\\n",
       "0          113.679592,23.632491;113.680586,23.632522      右转               []   \n",
       "1  113.680586,23.632522;113.680638,23.63214;113.6...  向右前方行走               []   \n",
       "2  113.680204,23.630838;113.680035,23.630773;113....      左转               []   \n",
       "3  113.678711,23.63036;113.678711,23.62934;113.67...      左转               []   \n",
       "4  113.678273,23.628368;113.678572,23.628338;113....      []            到达目的地   \n",
       "\n",
       "  walk_type  \n",
       "0         0  \n",
       "1         0  \n",
       "2         0  \n",
       "3         0  \n",
       "4         0  "
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "walking(my_key,'113.679287,23.632575','113.678652,23.628412')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 公交路径规划"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "公交路径规划 API 可以规划综合各类公共（火车、公交、地铁）交通方式的通勤方案，并且返回通勤方案的数据。\n",
    "\n",
    "\n",
    "URL: https://restapi.amap.com/v3/direction/transit/integrated?parameters\n",
    "\n",
    "请求方式:get\n",
    "\n",
    "文档： https://lbs.amap.com/api/webservice/guide/api/direction\n",
    "* 必选:key,origin，destination ,city\n",
    "\n",
    "(规则:（经度，纬度）经纬度小数点不超过6位)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'113.350961,23.131577'"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数据准备\n",
    "origin1 = geo(my_key,\"广东省暨南大学\",None)\n",
    "origin1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'113.264434,23.129162'"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "destination1 = geo(my_key,\"广州塔\",None)\n",
    "destination1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "def transit(key,origin,destination,city,cityd=None,extensions='base',strategy=None,nightflag=None,date=None,time=None,output=None,callback=None,sig=None)->str:\n",
    "    \"\"\"获取高德API地理编码\n",
    "    注释： key是指高德API密钥，请去注册\n",
    "    填入origin起点经纬度\n",
    "    destinaton终点经纬度\n",
    "    city城市/跨城规划时的起点城市\n",
    "    \"\"\"\n",
    "    url = \"https://restapi.amap.com/v3/direction/transit/integrated?parameters\"\n",
    "    params = {\n",
    "        \"key\":key,\n",
    "        \"origin\":origin,\n",
    "        \"destination\":destination,\n",
    "        \"city\":city,\n",
    "        \"cityd\":cityd,\n",
    "        \"extensions\":extensions,\n",
    "        \"strategy\":strategy,\n",
    "        \"nightflag\":nightflag,\n",
    "        \"date\":date,\n",
    "        \"time\":time,\n",
    "        \"sig\":sig,\n",
    "        \"output\":output,\n",
    "        \"callback\":callback\n",
    "        \n",
    "    }\n",
    "    Response  = requests.get(url,params=params)\n",
    "    a = Response.json()\n",
    "    #出发到站点\n",
    "    B_walk = pd.json_normalize(a['route']['transits'][0]['segments'][0]['walking']['steps'])\n",
    "    display(B_walk)\n",
    "    #巴士站点\n",
    "    B_bus = pd.json_normalize(a['route']['transits'][0]['segments'][0]['bus']['buslines'][0]['via_stops'])\n",
    "    display(B_bus)\n",
    "    #下车后到目的地\n",
    "    B_walk_stop = pd.json_normalize(a['route']['transits'][0]['segments'][1]['walking']['steps'])\n",
    "    display(B_walk_stop)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instruction</th>\n",
       "      <th>road</th>\n",
       "      <th>distance</th>\n",
       "      <th>duration</th>\n",
       "      <th>polyline</th>\n",
       "      <th>action</th>\n",
       "      <th>assistant_action</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>沿明湖南路步行37米左转</td>\n",
       "      <td>明湖南路</td>\n",
       "      <td>37</td>\n",
       "      <td>[]</td>\n",
       "      <td>113.350975,23.131445;113.351013,23.131449;113....</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>沿真如东路步行219米向右前方行走</td>\n",
       "      <td>真如东路</td>\n",
       "      <td>219</td>\n",
       "      <td>[]</td>\n",
       "      <td>113.351357,23.131479;113.351288,23.132196;113....</td>\n",
       "      <td>向右前方行走</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>沿真如东路步行311米右转</td>\n",
       "      <td>真如东路</td>\n",
       "      <td>311</td>\n",
       "      <td>[]</td>\n",
       "      <td>113.351105,23.133425;113.351105,23.133646;113....</td>\n",
       "      <td>右转</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>步行25米左转</td>\n",
       "      <td>[]</td>\n",
       "      <td>25</td>\n",
       "      <td>[]</td>\n",
       "      <td>113.349709,23.135386;113.349724,23.135477;113....</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>沿中山大道西辅路步行48米往前走</td>\n",
       "      <td>中山大道西辅路</td>\n",
       "      <td>48</td>\n",
       "      <td>[]</td>\n",
       "      <td>113.349762,23.135612;113.349297,23.135685</td>\n",
       "      <td>往前走</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>沿中山大道西步行176米向左前方行走</td>\n",
       "      <td>中山大道西</td>\n",
       "      <td>176</td>\n",
       "      <td>[]</td>\n",
       "      <td>113.349289,23.135685;113.347931,23.135933;113....</td>\n",
       "      <td>向左前方行走</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>步行104米左转</td>\n",
       "      <td>[]</td>\n",
       "      <td>104</td>\n",
       "      <td>[]</td>\n",
       "      <td>113.347603,23.135998;113.347580,23.135916;113....</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>沿中山大道西步行43米到达师大暨大</td>\n",
       "      <td>中山大道西</td>\n",
       "      <td>43</td>\n",
       "      <td>[]</td>\n",
       "      <td>113.347702,23.136307;113.347984,23.136259;113....</td>\n",
       "      <td>[]</td>\n",
       "      <td>到达师大暨大</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          instruction     road distance duration  \\\n",
       "0        沿明湖南路步行37米左转     明湖南路       37       []   \n",
       "1   沿真如东路步行219米向右前方行走     真如东路      219       []   \n",
       "2       沿真如东路步行311米右转     真如东路      311       []   \n",
       "3             步行25米左转       []       25       []   \n",
       "4    沿中山大道西辅路步行48米往前走  中山大道西辅路       48       []   \n",
       "5  沿中山大道西步行176米向左前方行走    中山大道西      176       []   \n",
       "6            步行104米左转       []      104       []   \n",
       "7   沿中山大道西步行43米到达师大暨大    中山大道西       43       []   \n",
       "\n",
       "                                            polyline  action assistant_action  \n",
       "0  113.350975,23.131445;113.351013,23.131449;113....      左转               []  \n",
       "1  113.351357,23.131479;113.351288,23.132196;113....  向右前方行走               []  \n",
       "2  113.351105,23.133425;113.351105,23.133646;113....      右转               []  \n",
       "3  113.349709,23.135386;113.349724,23.135477;113....      左转               []  \n",
       "4          113.349762,23.135612;113.349297,23.135685     往前走               []  \n",
       "5  113.349289,23.135685;113.347931,23.135933;113....  向左前方行走               []  \n",
       "6  113.347603,23.135998;113.347580,23.135916;113....      左转               []  \n",
       "7  113.347702,23.136307;113.347984,23.136259;113....      []           到达师大暨大  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>id</th>\n",
       "      <th>location</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>岗顶站</td>\n",
       "      <td>440100017356045</td>\n",
       "      <td>113.338381,23.134518</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>石牌桥</td>\n",
       "      <td>440100017356046</td>\n",
       "      <td>113.331528,23.133442</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>体育中心</td>\n",
       "      <td>440100017356047</td>\n",
       "      <td>113.323316,23.133815</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>锦城花园</td>\n",
       "      <td>440100017356048</td>\n",
       "      <td>113.310308,23.131793</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>东峻广场</td>\n",
       "      <td>440100017356030</td>\n",
       "      <td>113.306732,23.131927</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>东风东路站</td>\n",
       "      <td>440100017356031</td>\n",
       "      <td>113.302116,23.131800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>肿瘤医院</td>\n",
       "      <td>440100017356032</td>\n",
       "      <td>113.289467,23.130964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>越秀桥</td>\n",
       "      <td>440100017356049</td>\n",
       "      <td>113.279870,23.131254</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>正骨医院</td>\n",
       "      <td>440100017356034</td>\n",
       "      <td>113.273533,23.131042</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>东风中路</td>\n",
       "      <td>440100017356035</td>\n",
       "      <td>113.270252,23.131181</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>中山纪念堂(连新路)</td>\n",
       "      <td>440100017356059</td>\n",
       "      <td>113.263437,23.132496</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          name               id              location\n",
       "0          岗顶站  440100017356045  113.338381,23.134518\n",
       "1          石牌桥  440100017356046  113.331528,23.133442\n",
       "2         体育中心  440100017356047  113.323316,23.133815\n",
       "3         锦城花园  440100017356048  113.310308,23.131793\n",
       "4         东峻广场  440100017356030  113.306732,23.131927\n",
       "5        东风东路站  440100017356031  113.302116,23.131800\n",
       "6         肿瘤医院  440100017356032  113.289467,23.130964\n",
       "7          越秀桥  440100017356049  113.279870,23.131254\n",
       "8         正骨医院  440100017356034  113.273533,23.131042\n",
       "9         东风中路  440100017356035  113.270252,23.131181\n",
       "10  中山纪念堂(连新路)  440100017356059  113.263437,23.132496"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instruction</th>\n",
       "      <th>road</th>\n",
       "      <th>distance</th>\n",
       "      <th>duration</th>\n",
       "      <th>polyline</th>\n",
       "      <th>action</th>\n",
       "      <th>assistant_action</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>沿广仁路步行47米左转</td>\n",
       "      <td>广仁路</td>\n",
       "      <td>47</td>\n",
       "      <td>[]</td>\n",
       "      <td>113.267616,23.128658;113.267616,23.128841;113....</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>沿越华路步行212米左转</td>\n",
       "      <td>越华路</td>\n",
       "      <td>212</td>\n",
       "      <td>[]</td>\n",
       "      <td>113.267609,23.129084;113.267075,23.129093;113....</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>沿吉祥路步行35米右转</td>\n",
       "      <td>吉祥路</td>\n",
       "      <td>35</td>\n",
       "      <td>[]</td>\n",
       "      <td>113.265526,23.129002;113.265503,23.128685</td>\n",
       "      <td>右转</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>沿府前路步行57米右转</td>\n",
       "      <td>府前路</td>\n",
       "      <td>57</td>\n",
       "      <td>[]</td>\n",
       "      <td>113.265503,23.128681;113.264938,23.128719</td>\n",
       "      <td>右转</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>步行35米左转</td>\n",
       "      <td>[]</td>\n",
       "      <td>35</td>\n",
       "      <td>[]</td>\n",
       "      <td>113.264938,23.128719;113.264938,23.129036</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>步行52米</td>\n",
       "      <td>[]</td>\n",
       "      <td>52</td>\n",
       "      <td>[]</td>\n",
       "      <td>113.264938,23.129036;113.264771,23.128981;113....</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    instruction road distance duration  \\\n",
       "0   沿广仁路步行47米左转  广仁路       47       []   \n",
       "1  沿越华路步行212米左转  越华路      212       []   \n",
       "2   沿吉祥路步行35米右转  吉祥路       35       []   \n",
       "3   沿府前路步行57米右转  府前路       57       []   \n",
       "4       步行35米左转   []       35       []   \n",
       "5         步行52米   []       52       []   \n",
       "\n",
       "                                            polyline action assistant_action  \n",
       "0  113.267616,23.128658;113.267616,23.128841;113....     左转               []  \n",
       "1  113.267609,23.129084;113.267075,23.129093;113....     左转               []  \n",
       "2          113.265526,23.129002;113.265503,23.128685     右转               []  \n",
       "3          113.265503,23.128681;113.264938,23.128719     右转               []  \n",
       "4          113.264938,23.128719;113.264938,23.129036     左转               []  \n",
       "5  113.264938,23.129036;113.264771,23.128981;113....     []               []  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "transit(my_key,origin1,destination1,\"广州市\",'base')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 驾车路径规划\n",
    "驾车路径规划 API 可以规划以小客车、轿车通勤出行的方案，并且返回通勤方案的数据。\n",
    "\n",
    "url : https://restapi.amap.com/v3/direction/driving?parameters\n",
    "\n",
    "请求参数：key,orign,destination"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "def driving(key,origin,destination,destinationid=None,origintype=None,destinationtype=None)->str:\n",
    "    \"\"\"获取高德API地理编码\n",
    "    注释： key是指高德API密钥，请去注册\n",
    "    填入origin起点经纬度\n",
    "    destinaton终点经纬度\n",
    "    详情参数参考 ：https://lbs.amap.com/api/webservice/guide/api/direction\n",
    "    \n",
    "    \"\"\"\n",
    "    url = \"https://restapi.amap.com/v3/direction/driving?parameters\"\n",
    "    params = {\n",
    "        \"key\":key,\n",
    "        \"origin\":origin,\n",
    "        \"destination\":destination,\n",
    "        \"origintype\":origintype,\n",
    "        \"destinationtype\":destinationtype\n",
    "    }\n",
    "    r  = requests.get(url,params=params)\n",
    "    x=r.json()\n",
    "    \n",
    "    return  pd.json_normalize(x['route']['paths'][0]['steps'])#列表形式打印信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instruction</th>\n",
       "      <th>orientation</th>\n",
       "      <th>distance</th>\n",
       "      <th>tolls</th>\n",
       "      <th>toll_distance</th>\n",
       "      <th>toll_road</th>\n",
       "      <th>duration</th>\n",
       "      <th>polyline</th>\n",
       "      <th>action</th>\n",
       "      <th>assistant_action</th>\n",
       "      <th>tmcs</th>\n",
       "      <th>cities</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>向南行驶9米左转</td>\n",
       "      <td>南</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>7</td>\n",
       "      <td>113.679596,23.632574;113.679596,23.632491</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "      <td>[{'lcode': [], 'distance': '9', 'status': '未知'...</td>\n",
       "      <td>[{'name': '广州市', 'citycode': '020', 'adcode': ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>向东行驶100米右转</td>\n",
       "      <td>东</td>\n",
       "      <td>100</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>29</td>\n",
       "      <td>113.679596,23.632491;113.680582,23.632522</td>\n",
       "      <td>右转</td>\n",
       "      <td>[]</td>\n",
       "      <td>[{'lcode': [], 'distance': '100', 'status': '未...</td>\n",
       "      <td>[{'name': '广州市', 'citycode': '020', 'adcode': ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>向南行驶199米向右前方行驶</td>\n",
       "      <td>南</td>\n",
       "      <td>199</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>55</td>\n",
       "      <td>113.680582,23.632522;113.680642,23.632135;113....</td>\n",
       "      <td>向右前方行驶</td>\n",
       "      <td>[]</td>\n",
       "      <td>[{'lcode': [], 'distance': '122', 'status': '未...</td>\n",
       "      <td>[{'name': '广州市', 'citycode': '020', 'adcode': ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>向西行驶159米左转</td>\n",
       "      <td>西</td>\n",
       "      <td>159</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>38</td>\n",
       "      <td>113.680204,23.630838;113.68003,23.630768;113.6...</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "      <td>[{'lcode': [], 'distance': '18', 'status': '未知...</td>\n",
       "      <td>[{'name': '广州市', 'citycode': '020', 'adcode': ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>向南行驶237米左转</td>\n",
       "      <td>南</td>\n",
       "      <td>237</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>69</td>\n",
       "      <td>113.678711,23.63036;113.678711,23.629336;113.6...</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "      <td>[{'lcode': [], 'distance': '113', 'status': '未...</td>\n",
       "      <td>[{'name': '广州市', 'citycode': '020', 'adcode': ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>向东行驶36米到达目的地</td>\n",
       "      <td>东</td>\n",
       "      <td>36</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>12</td>\n",
       "      <td>113.678273,23.628372;113.678572,23.628333;113....</td>\n",
       "      <td>[]</td>\n",
       "      <td>到达目的地</td>\n",
       "      <td>[{'lcode': [], 'distance': '36', 'status': '未知...</td>\n",
       "      <td>[{'name': '广州市', 'citycode': '020', 'adcode': ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      instruction orientation distance tolls toll_distance toll_road duration  \\\n",
       "0        向南行驶9米左转           南        9     0             0        []        7   \n",
       "1      向东行驶100米右转           东      100     0             0        []       29   \n",
       "2  向南行驶199米向右前方行驶           南      199     0             0        []       55   \n",
       "3      向西行驶159米左转           西      159     0             0        []       38   \n",
       "4      向南行驶237米左转           南      237     0             0        []       69   \n",
       "5    向东行驶36米到达目的地           东       36     0             0        []       12   \n",
       "\n",
       "                                            polyline  action assistant_action  \\\n",
       "0          113.679596,23.632574;113.679596,23.632491      左转               []   \n",
       "1          113.679596,23.632491;113.680582,23.632522      右转               []   \n",
       "2  113.680582,23.632522;113.680642,23.632135;113....  向右前方行驶               []   \n",
       "3  113.680204,23.630838;113.68003,23.630768;113.6...      左转               []   \n",
       "4  113.678711,23.63036;113.678711,23.629336;113.6...      左转               []   \n",
       "5  113.678273,23.628372;113.678572,23.628333;113....      []            到达目的地   \n",
       "\n",
       "                                                tmcs  \\\n",
       "0  [{'lcode': [], 'distance': '9', 'status': '未知'...   \n",
       "1  [{'lcode': [], 'distance': '100', 'status': '未...   \n",
       "2  [{'lcode': [], 'distance': '122', 'status': '未...   \n",
       "3  [{'lcode': [], 'distance': '18', 'status': '未知...   \n",
       "4  [{'lcode': [], 'distance': '113', 'status': '未...   \n",
       "5  [{'lcode': [], 'distance': '36', 'status': '未知...   \n",
       "\n",
       "                                              cities  \n",
       "0  [{'name': '广州市', 'citycode': '020', 'adcode': ...  \n",
       "1  [{'name': '广州市', 'citycode': '020', 'adcode': ...  \n",
       "2  [{'name': '广州市', 'citycode': '020', 'adcode': ...  \n",
       "3  [{'name': '广州市', 'citycode': '020', 'adcode': ...  \n",
       "4  [{'name': '广州市', 'citycode': '020', 'adcode': ...  \n",
       "5  [{'name': '广州市', 'citycode': '020', 'adcode': ...  "
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aa = driving(my_key,'113.679287,23.632575','113.678652,23.628412')\n",
    "\n",
    "aa"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 行政区域查询\n",
    "行政区域查询是一类简单的HTTP接口，根据用户输入的搜索条件可以帮助用户快速的查找特定的行政区域信息。\n",
    "\n",
    "URL:https://restapi.amap.com/v3/config/district?parameters\n",
    "\n",
    "请求参数：key(必填)\n",
    "选填参数：keywords subdistrict\n",
    "\n",
    "**思考**\n",
    "帮助用户快速查找当地行政区域"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "def district(key,keywords:str,subdistrict=None,page=None,filter=None,offset=None,callback=None,output=None):\n",
    "    \"\"\"获取高德API地理编码\n",
    "    注释： key是指高德API密钥，请去注册\n",
    "    keywords查询关键字\n",
    "    subdistrict子级行政区\n",
    "    \"\"\"\n",
    "\n",
    "    url = \"https://restapi.amap.com/v3/config/district?parameters\"\n",
    "    params = {\n",
    "        \"key\":key,\n",
    "        \"keywords\":keywords,\n",
    "        \"subdistrict\":subdistrict,\n",
    "        \"page\":page,\n",
    "        \"filter\":filter,\n",
    "        \"offset\":offset,\n",
    "        \"callback\":callback,\n",
    "        \"output\":output\n",
    "        \n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    a = response.json()\n",
    "    return pd.json_normalize(a['districts'][0]['districts'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>citycode</th>\n",
       "      <th>adcode</th>\n",
       "      <th>name</th>\n",
       "      <th>center</th>\n",
       "      <th>level</th>\n",
       "      <th>districts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>020</td>\n",
       "      <td>440117</td>\n",
       "      <td>江埔街道</td>\n",
       "      <td>113.583,23.5107</td>\n",
       "      <td>street</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>020</td>\n",
       "      <td>440117</td>\n",
       "      <td>城郊街道</td>\n",
       "      <td>113.519,23.6542</td>\n",
       "      <td>street</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>020</td>\n",
       "      <td>440117</td>\n",
       "      <td>街口街道</td>\n",
       "      <td>113.581,23.5096</td>\n",
       "      <td>street</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>020</td>\n",
       "      <td>440117</td>\n",
       "      <td>吕田镇</td>\n",
       "      <td>113.853,23.8471</td>\n",
       "      <td>street</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>020</td>\n",
       "      <td>440117</td>\n",
       "      <td>流溪河林场</td>\n",
       "      <td>113.844,23.8201</td>\n",
       "      <td>street</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>020</td>\n",
       "      <td>440117</td>\n",
       "      <td>良口镇</td>\n",
       "      <td>113.793,23.8184</td>\n",
       "      <td>street</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>020</td>\n",
       "      <td>440117</td>\n",
       "      <td>黄龙带水库管理处</td>\n",
       "      <td>113.718,23.8369</td>\n",
       "      <td>street</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>020</td>\n",
       "      <td>440117</td>\n",
       "      <td>鳌头镇</td>\n",
       "      <td>113.517,23.5497</td>\n",
       "      <td>street</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>020</td>\n",
       "      <td>440117</td>\n",
       "      <td>太平镇</td>\n",
       "      <td>113.457,23.4819</td>\n",
       "      <td>street</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>020</td>\n",
       "      <td>440117</td>\n",
       "      <td>大岭山林场</td>\n",
       "      <td>113.73,23.6254</td>\n",
       "      <td>street</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>020</td>\n",
       "      <td>440117</td>\n",
       "      <td>温泉镇</td>\n",
       "      <td>113.828,23.6471</td>\n",
       "      <td>street</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   citycode  adcode      name           center   level districts\n",
       "0       020  440117      江埔街道  113.583,23.5107  street        []\n",
       "1       020  440117      城郊街道  113.519,23.6542  street        []\n",
       "2       020  440117      街口街道  113.581,23.5096  street        []\n",
       "3       020  440117       吕田镇  113.853,23.8471  street        []\n",
       "4       020  440117     流溪河林场  113.844,23.8201  street        []\n",
       "5       020  440117       良口镇  113.793,23.8184  street        []\n",
       "6       020  440117  黄龙带水库管理处  113.718,23.8369  street        []\n",
       "7       020  440117       鳌头镇  113.517,23.5497  street        []\n",
       "8       020  440117       太平镇  113.457,23.4819  street        []\n",
       "9       020  440117     大岭山林场   113.73,23.6254  street        []\n",
       "10      020  440117       温泉镇  113.828,23.6471  street        []"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = district(my_key,\"从化区\")#寻找从化区的行政区\n",
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 搜索POI\n",
    "\n",
    "搜索服务API是一类简单的HTTP接口，提供多种查询POI信息的能力，其中包括关键字搜索、周边搜索、多边形搜索、ID查询四种筛选机制。\n",
    "URL:https://restapi.amap.com/v3/place/text?parameters\n",
    "\n",
    "请求参数：key(必填)\n",
    "选填参数：keywords subdistrict\n",
    "\n",
    "**思考**\n",
    "\n",
    "* 根据用户搜索数据分析\n",
    "* 在广告推送时推送合适的POI\n",
    "* 精确投放"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "def place(key,keywords:str,types=None,city=None,citylimit=None,children=None,offset=None,extensions=None,sig=None,output=None,callback=None):\n",
    "    \"\"\"获取高德API地理编码\n",
    "    注释： key是指高德API密钥，请去注册\n",
    "    types 查询POI类型\n",
    "    可选值：分类代码 或 汉字（若用汉字，请严格按照附件之中的汉字填写）\n",
    "    \"\"\"\n",
    "\n",
    "    url = \"https://restapi.amap.com/v3/place/text?parameters\"\n",
    "    params = {\n",
    "        \"key\":key,\n",
    "        \"keywords\":keywords,\n",
    "        \"citylimit\":citylimit,\n",
    "        \"children\":children,\n",
    "        \"offset\":offset,\n",
    "        \"extensions\":extensions,\n",
    "        \"offset\":offset,\n",
    "        \"sig\":sig,\n",
    "        \"output\":output,\n",
    "        \"callback\":callback\n",
    "\n",
    "        \n",
    "    }\n",
    "    \n",
    "    response  = requests.get(url,params=params)\n",
    "    a = response.json()\n",
    "    return pd.json_normalize(a['pois'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>parent</th>\n",
       "      <th>address</th>\n",
       "      <th>distance</th>\n",
       "      <th>pname</th>\n",
       "      <th>importance</th>\n",
       "      <th>biz_type</th>\n",
       "      <th>cityname</th>\n",
       "      <th>type</th>\n",
       "      <th>photos</th>\n",
       "      <th>typecode</th>\n",
       "      <th>...</th>\n",
       "      <th>childtype</th>\n",
       "      <th>adname</th>\n",
       "      <th>name</th>\n",
       "      <th>location</th>\n",
       "      <th>tel</th>\n",
       "      <th>shopid</th>\n",
       "      <th>id</th>\n",
       "      <th>biz_ext.cost</th>\n",
       "      <th>biz_ext.rating</th>\n",
       "      <th>biz_ext.meal_ordering</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>[]</td>\n",
       "      <td>广从南路乌土村上围2队13号</td>\n",
       "      <td>[]</td>\n",
       "      <td>广东省</td>\n",
       "      <td>[]</td>\n",
       "      <td>diner</td>\n",
       "      <td>广州市</td>\n",
       "      <td>餐饮服务;餐饮相关场所;餐饮相关</td>\n",
       "      <td>[]</td>\n",
       "      <td>050000</td>\n",
       "      <td>...</td>\n",
       "      <td>[]</td>\n",
       "      <td>从化区</td>\n",
       "      <td>网红烤鱼饭</td>\n",
       "      <td>113.677982,23.617576</td>\n",
       "      <td>13068852663</td>\n",
       "      <td>[]</td>\n",
       "      <td>B0G3MU0JF6</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>[]</td>\n",
       "      <td>歌域商务酒店263号</td>\n",
       "      <td>[]</td>\n",
       "      <td>广东省</td>\n",
       "      <td>[]</td>\n",
       "      <td>diner</td>\n",
       "      <td>广州市</td>\n",
       "      <td>餐饮服务;中餐厅;台湾菜</td>\n",
       "      <td>[]</td>\n",
       "      <td>050122</td>\n",
       "      <td>...</td>\n",
       "      <td>[]</td>\n",
       "      <td>从化区</td>\n",
       "      <td>眷村阿嬷&amp;国民网红饭团</td>\n",
       "      <td>113.606065,23.529578</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>B0G23OGKIJ</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>[]</td>\n",
       "      <td>从化温泉镇中山大学南方学院明辩路2号</td>\n",
       "      <td>[]</td>\n",
       "      <td>广东省</td>\n",
       "      <td>[]</td>\n",
       "      <td>diner</td>\n",
       "      <td>广州市</td>\n",
       "      <td>餐饮服务;餐饮相关场所;餐饮相关</td>\n",
       "      <td>[]</td>\n",
       "      <td>050000</td>\n",
       "      <td>...</td>\n",
       "      <td>[]</td>\n",
       "      <td>从化区</td>\n",
       "      <td>网红小串店</td>\n",
       "      <td>113.679286,23.632573</td>\n",
       "      <td>13802426981</td>\n",
       "      <td>[]</td>\n",
       "      <td>B0FFLNRH1K</td>\n",
       "      <td>[]</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>[]</td>\n",
       "      <td>太平镇康乐东路24号</td>\n",
       "      <td>[]</td>\n",
       "      <td>广东省</td>\n",
       "      <td>[]</td>\n",
       "      <td>diner</td>\n",
       "      <td>广州市</td>\n",
       "      <td>餐饮服务;餐饮相关场所;餐饮相关</td>\n",
       "      <td>[]</td>\n",
       "      <td>050000</td>\n",
       "      <td>...</td>\n",
       "      <td>[]</td>\n",
       "      <td>从化区</td>\n",
       "      <td>尺艺樘</td>\n",
       "      <td>113.484255,23.431731</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>B0FFK1THTC</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>[]</td>\n",
       "      <td>青云路381号</td>\n",
       "      <td>[]</td>\n",
       "      <td>广东省</td>\n",
       "      <td>[]</td>\n",
       "      <td>diner</td>\n",
       "      <td>广州市</td>\n",
       "      <td>餐饮服务;甜品店;甜品店</td>\n",
       "      <td>[]</td>\n",
       "      <td>050900</td>\n",
       "      <td>...</td>\n",
       "      <td>[]</td>\n",
       "      <td>从化区</td>\n",
       "      <td>妙旺角生日蛋糕(从化分店)</td>\n",
       "      <td>113.582981,23.535589</td>\n",
       "      <td>14739340071</td>\n",
       "      <td>[]</td>\n",
       "      <td>B0GR6KX2K3</td>\n",
       "      <td>[]</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>[]</td>\n",
       "      <td>江埔街河东南路52-四</td>\n",
       "      <td>[]</td>\n",
       "      <td>广东省</td>\n",
       "      <td>[]</td>\n",
       "      <td>diner</td>\n",
       "      <td>广州市</td>\n",
       "      <td>餐饮服务;中餐厅;中餐厅</td>\n",
       "      <td>[]</td>\n",
       "      <td>050100</td>\n",
       "      <td>...</td>\n",
       "      <td>[]</td>\n",
       "      <td>从化区</td>\n",
       "      <td>粥多点(暂停营业)</td>\n",
       "      <td>113.596896,23.542093</td>\n",
       "      <td>13327278319</td>\n",
       "      <td>[]</td>\n",
       "      <td>B0FFKT4JLQ</td>\n",
       "      <td>[]</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>[]</td>\n",
       "      <td>府前路与建云东路交叉口西北100米</td>\n",
       "      <td>[]</td>\n",
       "      <td>广东省</td>\n",
       "      <td>[]</td>\n",
       "      <td>diner</td>\n",
       "      <td>广州市</td>\n",
       "      <td>餐饮服务;糕饼店;糕饼店</td>\n",
       "      <td>[{'provider': [], 'title': [], 'url': 'http://...</td>\n",
       "      <td>050800</td>\n",
       "      <td>...</td>\n",
       "      <td>[]</td>\n",
       "      <td>从化区</td>\n",
       "      <td>四悦蛋糕店</td>\n",
       "      <td>113.587614,23.543358</td>\n",
       "      <td>18818803520</td>\n",
       "      <td>[]</td>\n",
       "      <td>B0FFJKKPG7</td>\n",
       "      <td>15.00</td>\n",
       "      <td>4.8</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>[]</td>\n",
       "      <td>青云路381号(从丰酸菜鱼斜对面)</td>\n",
       "      <td>[]</td>\n",
       "      <td>广东省</td>\n",
       "      <td>[]</td>\n",
       "      <td>diner</td>\n",
       "      <td>广州市</td>\n",
       "      <td>餐饮服务;糕饼店;糕饼店</td>\n",
       "      <td>[{'provider': [], 'title': [], 'url': 'http://...</td>\n",
       "      <td>050800</td>\n",
       "      <td>...</td>\n",
       "      <td>[]</td>\n",
       "      <td>从化区</td>\n",
       "      <td>小刀小蛋糕店</td>\n",
       "      <td>113.582839,23.535805</td>\n",
       "      <td>18922181480</td>\n",
       "      <td>[]</td>\n",
       "      <td>B0FFK0FOUI</td>\n",
       "      <td>19.00</td>\n",
       "      <td>4.6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>[]</td>\n",
       "      <td>碧泉路52号</td>\n",
       "      <td>[]</td>\n",
       "      <td>广东省</td>\n",
       "      <td>[]</td>\n",
       "      <td>diner</td>\n",
       "      <td>广州市</td>\n",
       "      <td>餐饮服务;中餐厅;中餐厅|餐饮服务;休闲餐饮场所;休闲餐饮场所</td>\n",
       "      <td>[{'provider': [], 'title': [], 'url': 'http://...</td>\n",
       "      <td>050100|050400</td>\n",
       "      <td>...</td>\n",
       "      <td>[]</td>\n",
       "      <td>从化区</td>\n",
       "      <td>夜妖音乐餐吧</td>\n",
       "      <td>113.655767,23.645799</td>\n",
       "      <td>13711418184;13729843683</td>\n",
       "      <td>[]</td>\n",
       "      <td>B0FFIZ5AQS</td>\n",
       "      <td>50.00</td>\n",
       "      <td>4.5</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>[]</td>\n",
       "      <td>新城中路18号</td>\n",
       "      <td>[]</td>\n",
       "      <td>广东省</td>\n",
       "      <td>[]</td>\n",
       "      <td>diner</td>\n",
       "      <td>广州市</td>\n",
       "      <td>餐饮服务;快餐厅;快餐厅</td>\n",
       "      <td>[{'provider': [], 'title': [], 'url': 'http://...</td>\n",
       "      <td>050300</td>\n",
       "      <td>...</td>\n",
       "      <td>[]</td>\n",
       "      <td>从化区</td>\n",
       "      <td>柳州螺蛳粉</td>\n",
       "      <td>113.585236,23.548664</td>\n",
       "      <td>13066332169;13926252535</td>\n",
       "      <td>[]</td>\n",
       "      <td>B0G17UXLBF</td>\n",
       "      <td>[]</td>\n",
       "      <td>4.6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>[]</td>\n",
       "      <td>江埔街尚景路128号</td>\n",
       "      <td>[]</td>\n",
       "      <td>广东省</td>\n",
       "      <td>[]</td>\n",
       "      <td>diner</td>\n",
       "      <td>广州市</td>\n",
       "      <td>餐饮服务;糕饼店;糕饼店</td>\n",
       "      <td>[{'provider': [], 'title': [], 'url': 'http://...</td>\n",
       "      <td>050800</td>\n",
       "      <td>...</td>\n",
       "      <td>[]</td>\n",
       "      <td>从化区</td>\n",
       "      <td>可点烘焙</td>\n",
       "      <td>113.594736,23.533191</td>\n",
       "      <td>13711425104</td>\n",
       "      <td>[]</td>\n",
       "      <td>B0FFKVYJMY</td>\n",
       "      <td>[]</td>\n",
       "      <td>4.3</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>[]</td>\n",
       "      <td>碧泉路一横街二巷57号(新子谷温泉酒店旁)</td>\n",
       "      <td>[]</td>\n",
       "      <td>广东省</td>\n",
       "      <td>[]</td>\n",
       "      <td>diner</td>\n",
       "      <td>广州市</td>\n",
       "      <td>餐饮服务;中餐厅;中餐厅</td>\n",
       "      <td>[]</td>\n",
       "      <td>050100</td>\n",
       "      <td>...</td>\n",
       "      <td>[]</td>\n",
       "      <td>从化区</td>\n",
       "      <td>夜宴音乐餐吧·椰子鸡·烤鱼</td>\n",
       "      <td>113.655798,23.645435</td>\n",
       "      <td>13711418184</td>\n",
       "      <td>[]</td>\n",
       "      <td>B0G3ZCS7DW</td>\n",
       "      <td>55.00</td>\n",
       "      <td>3.6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>[]</td>\n",
       "      <td>街口街朝阳街34号(广百北门对面)</td>\n",
       "      <td>[]</td>\n",
       "      <td>广东省</td>\n",
       "      <td>[]</td>\n",
       "      <td>diner</td>\n",
       "      <td>广州市</td>\n",
       "      <td>餐饮服务;冷饮店;冷饮店</td>\n",
       "      <td>[{'provider': [], 'title': [], 'url': 'http://...</td>\n",
       "      <td>050700</td>\n",
       "      <td>...</td>\n",
       "      <td>[]</td>\n",
       "      <td>从化区</td>\n",
       "      <td>茶源轩奶茶店</td>\n",
       "      <td>113.589465,23.549338</td>\n",
       "      <td>020-87948817</td>\n",
       "      <td>[]</td>\n",
       "      <td>B00141P0Z0</td>\n",
       "      <td>[]</td>\n",
       "      <td>4.2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>[]</td>\n",
       "      <td>桃莲村自编00823号</td>\n",
       "      <td>[]</td>\n",
       "      <td>广东省</td>\n",
       "      <td>[]</td>\n",
       "      <td>diner</td>\n",
       "      <td>广州市</td>\n",
       "      <td>餐饮服务;快餐厅;快餐厅</td>\n",
       "      <td>[]</td>\n",
       "      <td>050300</td>\n",
       "      <td>...</td>\n",
       "      <td>[]</td>\n",
       "      <td>从化区</td>\n",
       "      <td>加多堡·炸鸡汉堡</td>\n",
       "      <td>113.684131,23.630277</td>\n",
       "      <td>17806786688</td>\n",
       "      <td>[]</td>\n",
       "      <td>B0FFKTDLXL</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>[]</td>\n",
       "      <td>海塱村45号</td>\n",
       "      <td>[]</td>\n",
       "      <td>广东省</td>\n",
       "      <td>[]</td>\n",
       "      <td>diner</td>\n",
       "      <td>广州市</td>\n",
       "      <td>餐饮服务;糕饼店;糕饼店</td>\n",
       "      <td>[{'provider': [], 'title': [], 'url': 'http://...</td>\n",
       "      <td>050800</td>\n",
       "      <td>...</td>\n",
       "      <td>[]</td>\n",
       "      <td>从化区</td>\n",
       "      <td>自啡在DIY</td>\n",
       "      <td>113.589222,23.531699</td>\n",
       "      <td>13119573711</td>\n",
       "      <td>[]</td>\n",
       "      <td>B0FFGIRBDS</td>\n",
       "      <td>53.00</td>\n",
       "      <td>4.7</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>[]</td>\n",
       "      <td>江湾路(江埔欣荣宏广场109号)</td>\n",
       "      <td>[]</td>\n",
       "      <td>广东省</td>\n",
       "      <td>[]</td>\n",
       "      <td>diner</td>\n",
       "      <td>广州市</td>\n",
       "      <td>餐饮服务;冷饮店;冷饮店</td>\n",
       "      <td>[{'provider': [], 'title': [], 'url': 'http://...</td>\n",
       "      <td>050700</td>\n",
       "      <td>...</td>\n",
       "      <td>[]</td>\n",
       "      <td>从化区</td>\n",
       "      <td>清新强力凉茶</td>\n",
       "      <td>113.588143,23.531195</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>B0FFFT2Q4B</td>\n",
       "      <td>[]</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>[]</td>\n",
       "      <td>回归路与回归路三巷交叉口西50米(幼儿园旁)</td>\n",
       "      <td>[]</td>\n",
       "      <td>广东省</td>\n",
       "      <td>[]</td>\n",
       "      <td>diner</td>\n",
       "      <td>广州市</td>\n",
       "      <td>餐饮服务;餐饮相关场所;餐饮相关|购物服务;购物相关场所;购物相关场所</td>\n",
       "      <td>[{'provider': [], 'title': [], 'url': 'http://...</td>\n",
       "      <td>050000|060000</td>\n",
       "      <td>...</td>\n",
       "      <td>[]</td>\n",
       "      <td>从化区</td>\n",
       "      <td>美冠</td>\n",
       "      <td>113.491991,23.441087</td>\n",
       "      <td>13059102417</td>\n",
       "      <td>[]</td>\n",
       "      <td>B0FFFYH4M7</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>B0FFF04ASX</td>\n",
       "      <td>广从南路</td>\n",
       "      <td>[]</td>\n",
       "      <td>广东省</td>\n",
       "      <td>[]</td>\n",
       "      <td>diner</td>\n",
       "      <td>广州市</td>\n",
       "      <td>餐饮服务;快餐厅;茶餐厅|餐饮服务;茶艺馆;茶艺馆</td>\n",
       "      <td>[{'provider': [], 'title': [], 'url': 'http://...</td>\n",
       "      <td>050305|050600</td>\n",
       "      <td>...</td>\n",
       "      <td>202</td>\n",
       "      <td>从化区</td>\n",
       "      <td>龙茶一品</td>\n",
       "      <td>113.491379,23.448482</td>\n",
       "      <td>13332832313</td>\n",
       "      <td>[]</td>\n",
       "      <td>B0FFG8YW27</td>\n",
       "      <td>58.00</td>\n",
       "      <td>4.2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>[]</td>\n",
       "      <td>从城大道164号</td>\n",
       "      <td>[]</td>\n",
       "      <td>广东省</td>\n",
       "      <td>[]</td>\n",
       "      <td>diner</td>\n",
       "      <td>广州市</td>\n",
       "      <td>餐饮服务;餐饮相关场所;餐饮相关</td>\n",
       "      <td>[{'provider': [], 'title': [], 'url': 'http://...</td>\n",
       "      <td>050000</td>\n",
       "      <td>...</td>\n",
       "      <td>[]</td>\n",
       "      <td>从化区</td>\n",
       "      <td>叶子咖啡(创客店)</td>\n",
       "      <td>113.596243,23.529338</td>\n",
       "      <td>13539441524;18922480382</td>\n",
       "      <td>[]</td>\n",
       "      <td>B0FFIIIL7G</td>\n",
       "      <td>18.00</td>\n",
       "      <td>3.9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>[]</td>\n",
       "      <td>江埔街从城大道欣荣宏商贸城从化大道南海塱横街41号</td>\n",
       "      <td>[]</td>\n",
       "      <td>广东省</td>\n",
       "      <td>[]</td>\n",
       "      <td>diner</td>\n",
       "      <td>广州市</td>\n",
       "      <td>餐饮服务;咖啡厅;咖啡厅</td>\n",
       "      <td>[{'provider': [], 'title': [], 'url': 'http://...</td>\n",
       "      <td>050500</td>\n",
       "      <td>...</td>\n",
       "      <td>[]</td>\n",
       "      <td>从化区</td>\n",
       "      <td>吖章咖啡(欣荣宏店)</td>\n",
       "      <td>113.590419,23.530544</td>\n",
       "      <td>18620265527;13729869388</td>\n",
       "      <td>[]</td>\n",
       "      <td>B0FFH5GVJ5</td>\n",
       "      <td>33.00</td>\n",
       "      <td>4.3</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>20 rows × 22 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        parent                    address distance pname importance biz_type  \\\n",
       "0           []             广从南路乌土村上围2队13号       []   广东省         []    diner   \n",
       "1           []                 歌域商务酒店263号       []   广东省         []    diner   \n",
       "2           []         从化温泉镇中山大学南方学院明辩路2号       []   广东省         []    diner   \n",
       "3           []                 太平镇康乐东路24号       []   广东省         []    diner   \n",
       "4           []                    青云路381号       []   广东省         []    diner   \n",
       "5           []                江埔街河东南路52-四       []   广东省         []    diner   \n",
       "6           []          府前路与建云东路交叉口西北100米       []   广东省         []    diner   \n",
       "7           []          青云路381号(从丰酸菜鱼斜对面)       []   广东省         []    diner   \n",
       "8           []                     碧泉路52号       []   广东省         []    diner   \n",
       "9           []                    新城中路18号       []   广东省         []    diner   \n",
       "10          []                 江埔街尚景路128号       []   广东省         []    diner   \n",
       "11          []      碧泉路一横街二巷57号(新子谷温泉酒店旁)       []   广东省         []    diner   \n",
       "12          []          街口街朝阳街34号(广百北门对面)       []   广东省         []    diner   \n",
       "13          []                桃莲村自编00823号       []   广东省         []    diner   \n",
       "14          []                     海塱村45号       []   广东省         []    diner   \n",
       "15          []           江湾路(江埔欣荣宏广场109号)       []   广东省         []    diner   \n",
       "16          []     回归路与回归路三巷交叉口西50米(幼儿园旁)       []   广东省         []    diner   \n",
       "17  B0FFF04ASX                       广从南路       []   广东省         []    diner   \n",
       "18          []                   从城大道164号       []   广东省         []    diner   \n",
       "19          []  江埔街从城大道欣荣宏商贸城从化大道南海塱横街41号       []   广东省         []    diner   \n",
       "\n",
       "   cityname                                 type  \\\n",
       "0       广州市                     餐饮服务;餐饮相关场所;餐饮相关   \n",
       "1       广州市                         餐饮服务;中餐厅;台湾菜   \n",
       "2       广州市                     餐饮服务;餐饮相关场所;餐饮相关   \n",
       "3       广州市                     餐饮服务;餐饮相关场所;餐饮相关   \n",
       "4       广州市                         餐饮服务;甜品店;甜品店   \n",
       "5       广州市                         餐饮服务;中餐厅;中餐厅   \n",
       "6       广州市                         餐饮服务;糕饼店;糕饼店   \n",
       "7       广州市                         餐饮服务;糕饼店;糕饼店   \n",
       "8       广州市      餐饮服务;中餐厅;中餐厅|餐饮服务;休闲餐饮场所;休闲餐饮场所   \n",
       "9       广州市                         餐饮服务;快餐厅;快餐厅   \n",
       "10      广州市                         餐饮服务;糕饼店;糕饼店   \n",
       "11      广州市                         餐饮服务;中餐厅;中餐厅   \n",
       "12      广州市                         餐饮服务;冷饮店;冷饮店   \n",
       "13      广州市                         餐饮服务;快餐厅;快餐厅   \n",
       "14      广州市                         餐饮服务;糕饼店;糕饼店   \n",
       "15      广州市                         餐饮服务;冷饮店;冷饮店   \n",
       "16      广州市  餐饮服务;餐饮相关场所;餐饮相关|购物服务;购物相关场所;购物相关场所   \n",
       "17      广州市            餐饮服务;快餐厅;茶餐厅|餐饮服务;茶艺馆;茶艺馆   \n",
       "18      广州市                     餐饮服务;餐饮相关场所;餐饮相关   \n",
       "19      广州市                         餐饮服务;咖啡厅;咖啡厅   \n",
       "\n",
       "                                               photos       typecode  ...  \\\n",
       "0                                                  []         050000  ...   \n",
       "1                                                  []         050122  ...   \n",
       "2                                                  []         050000  ...   \n",
       "3                                                  []         050000  ...   \n",
       "4                                                  []         050900  ...   \n",
       "5                                                  []         050100  ...   \n",
       "6   [{'provider': [], 'title': [], 'url': 'http://...         050800  ...   \n",
       "7   [{'provider': [], 'title': [], 'url': 'http://...         050800  ...   \n",
       "8   [{'provider': [], 'title': [], 'url': 'http://...  050100|050400  ...   \n",
       "9   [{'provider': [], 'title': [], 'url': 'http://...         050300  ...   \n",
       "10  [{'provider': [], 'title': [], 'url': 'http://...         050800  ...   \n",
       "11                                                 []         050100  ...   \n",
       "12  [{'provider': [], 'title': [], 'url': 'http://...         050700  ...   \n",
       "13                                                 []         050300  ...   \n",
       "14  [{'provider': [], 'title': [], 'url': 'http://...         050800  ...   \n",
       "15  [{'provider': [], 'title': [], 'url': 'http://...         050700  ...   \n",
       "16  [{'provider': [], 'title': [], 'url': 'http://...  050000|060000  ...   \n",
       "17  [{'provider': [], 'title': [], 'url': 'http://...  050305|050600  ...   \n",
       "18  [{'provider': [], 'title': [], 'url': 'http://...         050000  ...   \n",
       "19  [{'provider': [], 'title': [], 'url': 'http://...         050500  ...   \n",
       "\n",
       "   childtype adname           name              location  \\\n",
       "0         []    从化区          网红烤鱼饭  113.677982,23.617576   \n",
       "1         []    从化区    眷村阿嬷&国民网红饭团  113.606065,23.529578   \n",
       "2         []    从化区          网红小串店  113.679286,23.632573   \n",
       "3         []    从化区            尺艺樘  113.484255,23.431731   \n",
       "4         []    从化区  妙旺角生日蛋糕(从化分店)  113.582981,23.535589   \n",
       "5         []    从化区      粥多点(暂停营业)  113.596896,23.542093   \n",
       "6         []    从化区          四悦蛋糕店  113.587614,23.543358   \n",
       "7         []    从化区         小刀小蛋糕店  113.582839,23.535805   \n",
       "8         []    从化区         夜妖音乐餐吧  113.655767,23.645799   \n",
       "9         []    从化区          柳州螺蛳粉  113.585236,23.548664   \n",
       "10        []    从化区           可点烘焙  113.594736,23.533191   \n",
       "11        []    从化区  夜宴音乐餐吧·椰子鸡·烤鱼  113.655798,23.645435   \n",
       "12        []    从化区         茶源轩奶茶店  113.589465,23.549338   \n",
       "13        []    从化区       加多堡·炸鸡汉堡  113.684131,23.630277   \n",
       "14        []    从化区         自啡在DIY  113.589222,23.531699   \n",
       "15        []    从化区         清新强力凉茶  113.588143,23.531195   \n",
       "16        []    从化区             美冠  113.491991,23.441087   \n",
       "17       202    从化区           龙茶一品  113.491379,23.448482   \n",
       "18        []    从化区      叶子咖啡(创客店)  113.596243,23.529338   \n",
       "19        []    从化区     吖章咖啡(欣荣宏店)  113.590419,23.530544   \n",
       "\n",
       "                        tel shopid          id biz_ext.cost biz_ext.rating  \\\n",
       "0               13068852663     []  B0G3MU0JF6           []             []   \n",
       "1                        []     []  B0G23OGKIJ           []             []   \n",
       "2               13802426981     []  B0FFLNRH1K           []            1.0   \n",
       "3                        []     []  B0FFK1THTC           []             []   \n",
       "4               14739340071     []  B0GR6KX2K3           []            4.0   \n",
       "5               13327278319     []  B0FFKT4JLQ           []            4.0   \n",
       "6               18818803520     []  B0FFJKKPG7        15.00            4.8   \n",
       "7               18922181480     []  B0FFK0FOUI        19.00            4.6   \n",
       "8   13711418184;13729843683     []  B0FFIZ5AQS        50.00            4.5   \n",
       "9   13066332169;13926252535     []  B0G17UXLBF           []            4.6   \n",
       "10              13711425104     []  B0FFKVYJMY           []            4.3   \n",
       "11              13711418184     []  B0G3ZCS7DW        55.00            3.6   \n",
       "12             020-87948817     []  B00141P0Z0           []            4.2   \n",
       "13              17806786688     []  B0FFKTDLXL           []             []   \n",
       "14              13119573711     []  B0FFGIRBDS        53.00            4.7   \n",
       "15                       []     []  B0FFFT2Q4B           []            3.0   \n",
       "16              13059102417     []  B0FFFYH4M7           []             []   \n",
       "17              13332832313     []  B0FFG8YW27        58.00            4.2   \n",
       "18  13539441524;18922480382     []  B0FFIIIL7G        18.00            3.9   \n",
       "19  18620265527;13729869388     []  B0FFH5GVJ5        33.00            4.3   \n",
       "\n",
       "   biz_ext.meal_ordering  \n",
       "0                      0  \n",
       "1                      0  \n",
       "2                      0  \n",
       "3                      0  \n",
       "4                      0  \n",
       "5                      0  \n",
       "6                      0  \n",
       "7                      0  \n",
       "8                      0  \n",
       "9                      0  \n",
       "10                     0  \n",
       "11                     0  \n",
       "12                     0  \n",
       "13                     0  \n",
       "14                     0  \n",
       "15                     0  \n",
       "16                     0  \n",
       "17                     0  \n",
       "18                     0  \n",
       "19                     0  \n",
       "\n",
       "[20 rows x 22 columns]"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "从化POI = place(my_key,\"美食\" \"从化\" \"网红\")#可填写多个关键词\n",
    "从化POI "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# IP定位\n",
    "\n",
    "IP定位是一个简单的HTTP接口，根据用户输入的IP地址，能够快速的帮用户定位IP的所在位置。\n",
    "\n",
    "URL:https://restapi.amap.com/v3/ip?parameters\n",
    "\n",
    "* 请求参数：key(必填)\n",
    "* 选填参数：ip sig output\n",
    "\n",
    "**思考**\n",
    "\n",
    "* 帮助减少骚扰电话\n",
    "* 帮助定位追踪罪犯"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "def place(key,ip,sig=None,output=None):\n",
    "    \"\"\"获取高德API地理编码\n",
    "    注释： key是指高德API密钥，请去注册\n",
    "    ip地址 需要搜索的IP地址（仅支持国内）\n",
    "    若用户不填写IP，则取客户http之中的请求来进行定位\n",
    "    \n",
    "    \"\"\"\n",
    "\n",
    "    url = \"https://restapi.amap.com/v3/ip?parameters\"\n",
    "    params = {\n",
    "        \"key\":key,\n",
    "        \"ip\":ip,\n",
    "        \"sig\":sig,\n",
    "        \"output\":output,\n",
    "        \n",
    "    }\n",
    "    \n",
    "    response  = requests.get(url,params=params)\n",
    "    return response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'province': '广东省',\n",
       " 'city': '广州市',\n",
       " 'adcode': '440100',\n",
       " 'rectangle': '113.1017375,22.93212254;113.6770499,23.3809537'}"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "place(my_key,'61.242.54.130')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 批量请求接口\n",
    "在此必须特别说明，使用批量接口时，key的配额和QPS会根据子请求来进行控制。\n",
    "\n",
    "例如：一次批量请求里面有20个驾车路径规划请求，且在同一秒发来请求，则此key的QPS消耗为20\n",
    "\n",
    "一、申请”web服务 API”密钥（Key）；\n",
    "\n",
    "二、拼接请求，第一步申请的Key需作为必填参数一同发送，父请求的Key和子请求的Key请务必保持一致；\n",
    "\n",
    "三、batch接口本身为post请求接口，子请求只支持get方式请求，以json形式返回数据结构；子请求参数请参考各接口文档进行拼接，如无特殊声明，接口的输入参数和输出数据编码全部统一为UTF-8；\n",
    "\n",
    "四、默认所有的子请求都会继承当前请求的header头；\n",
    "\n",
    "五、为了保证以后升级兼容，建议header里指明Content-Type：application/json；\n",
    "\n",
    "六、batch接口当前支持所有v3（请求中带v3字样）接口。\n",
    "\n",
    "\n",
    "## 特别说明：受产品策略调整影响，自2020年11月起，建议您不再使用此批量接口。后续平台会逐步废弃并下线此服务。\n",
    "\n",
    "**思考**\n",
    "* 提高处理效率"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 静态地图\n",
    "\n",
    "静态地图服务通过返回一张地图图片响应HTTP请求，使用户能够将高德地图以图片形式嵌入自己的网页中。用户可以指定请求的地图位置、图片大小、以及在地图上添加覆盖物，如标签、标注、折线、多边形。\n",
    "\n",
    "URL:https://restapi.amap.com/v3/staticmap?parameters\n",
    "\n",
    "请求参数：key(必填)location(部分必填)\n",
    "选填参数：zoom  size\n",
    "\n",
    "**思考**\n",
    "\n",
    "* 获取用户所需地图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [],
   "source": [
    "def staticmap(key,location,zoom:str,size=None,scale=None,markers=None,labels=None,paths=None,traffic=None,sig=None):\n",
    "    \"\"\"获取高德API地理编码\n",
    "    注释： key是指高德API密钥，请去注册\n",
    "   location:地图中心点 经度和纬度\n",
    "   zoom:地图级别\n",
    "    \n",
    "    \"\"\"\n",
    "\n",
    "    url = \"https://restapi.amap.com/v3/staticmap?parameters\"\n",
    "    params = {\n",
    "        \"key\":key,\n",
    "        \"location\":location,\n",
    "        \"zoom\":zoom,\n",
    "        \"size\":size,\n",
    "        \"scale\":scale,\n",
    "        \"markers\":markers,\n",
    "        \"labels\":labels,\n",
    "        \"paths\":paths,\n",
    "        \"traffic\":traffic,\n",
    "        \"sig\":sig\n",
    "    }\n",
    "    \n",
    "    response  = requests.get(url,params=params)\n",
    "    data = response.url\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'https://restapi.amap.com/v3/staticmap?parameters&key=12f80238641864b66003f76e69819ee4&location=113.679287%2C23.632575&zoom=15'"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "map = staticmap(my_key,'113.679287,23.632575',zoom=15)\n",
    "map"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 坐标转换\n",
    "坐标转换是一类简单的HTTP接口，能够将用户输入的非高德坐标（GPS坐标、mapbar坐标、baidu坐标）转换成高德坐标。\n",
    "\n",
    "URL：https://restapi.amap.com/v3/assistant/coordinate/convert?parameters\n",
    "\n",
    "请求方式：GET\n",
    "\n",
    "* 请求参数：key(必填)location(必填)\n",
    "* 选填参数：coordsys sig output\n",
    "\n",
    "***思考***\n",
    "\n",
    "批量数据转化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "def assistant(key,locations,coordsyss=None):\n",
    "    \"\"\"获取高德API地理编码\n",
    "    注释： key是指高德API密钥，请去注册\n",
    "   location:地图中心点 经度和纬度\n",
    "   coordsys:原坐标系\n",
    "    \"\"\"\n",
    "    url = \"https://restapi.amap.com/v3/assistant/coordinate/convert?parameters\"\n",
    "    parameters = {\n",
    "        \"key\":key,\n",
    "        \"locations\":locations,\n",
    "        \"coordsyss\":coordsyss,\n",
    "        \"output\":json\n",
    "    }\n",
    "    \n",
    "    response  = requests.get(url,params=parameters)\n",
    "    return response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'info': 'ok',\n",
       " 'infocode': '10000',\n",
       " 'locations': '116.481499,39.990475|116.481499,39.990375'}"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "assistant(my_key,\"116.481499,39.990475|116.481499,39.990375\",'gps')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 天气查询 \n",
    "天气查询是一个简单的HTTP接口，根据用户输入的adcode，查询目标区域当前/未来的天气情况。\n",
    "\n",
    "URL\n",
    "\n",
    "https://restapi.amap.com/v3/weather/weatherInfo?parameters\n",
    "\n",
    "* 请求参数：key(必填)city(必填)\n",
    "* 选填参数：extensions\n",
    "\n",
    "***思考***\n",
    "* 汽车导航天气预报"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "def weather(key,city,extensions=None,output=None):\n",
    "    \"\"\"获取高德API地理编码\n",
    "    注释： key是指高德API密钥，请去注册\n",
    "         extensions气象类型\n",
    "        可选值：base/all\n",
    "         base:返回实况天气\n",
    "          all:返回预报天气\n",
    "    \"\"\"\n",
    "    url = \"https://restapi.amap.com/v3/weather/weatherInfo?parameters\"\n",
    "    parameters = {\n",
    "        \"key\":key,\n",
    "        \"city\":city,\n",
    "        \"extensions\":extensions,\n",
    "        \"output\":json\n",
    "    }\n",
    "    \n",
    "    response  = requests.get(url,params=parameters)\n",
    "    return response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'count': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'lives': [{'province': '北京',\n",
       "   'city': '东城区',\n",
       "   'adcode': '110101',\n",
       "   'weather': '霾',\n",
       "   'temperature': '9',\n",
       "   'winddirection': '东',\n",
       "   'windpower': '≤3',\n",
       "   'humidity': '65',\n",
       "   'reporttime': '2020-11-16 09:01:08'}]}"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "weather(my_key,'110101')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 输入提示\n",
    "输入提示是一类简单的HTTP接口，提供根据用户输入的关键词查询返回建议列表。\n",
    "\n",
    "URL\n",
    "\n",
    "https://restapi.amap.com/v3/assistant/inputtips?parameters\n",
    "\n",
    "* 请求参数：key(必填)keywords(必填)\n",
    "\n",
    "***思考***\n",
    "* 广告推送\n",
    "* 用户推荐系统"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "def ts(key,keywords,type=None,location=None,city=None,citylimit=None,datatype=None,sig=None,output=None,callback=None):\n",
    "    \"\"\"获取高德API地理编码\n",
    "    注释： key是指高德API密钥，请去注册\n",
    "         type:POI分类\n",
    "         location:坐标\n",
    "         \n",
    "    \"\"\"\n",
    "    url = \"https://restapi.amap.com/v3/assistant/inputtips?parameters\"\n",
    "    parameters = {\n",
    "        \"key\":key,\n",
    "        \"keywords\":keywords,\n",
    "        \"type\":type,\n",
    "        \"location\":location,\n",
    "        \"city\":city,\n",
    "        \"citylimit\":citylimit,\n",
    "        \"datatype\":datatype,\n",
    "        \"sig\":sig,\n",
    "        \"callback\":callback,\n",
    "        \"output\":json\n",
    "    }\n",
    "    \n",
    "    response  = requests.get(url,params=parameters)\n",
    "    a = response.json()\n",
    "    return pd.json_normalize(a['tips'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>district</th>\n",
       "      <th>adcode</th>\n",
       "      <th>location</th>\n",
       "      <th>address</th>\n",
       "      <th>typecode</th>\n",
       "      <th>city</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>[]</td>\n",
       "      <td>肯德基</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>B0FFKEPXS2</td>\n",
       "      <td>肯德基(望京西店)</td>\n",
       "      <td>北京市朝阳区</td>\n",
       "      <td>110105</td>\n",
       "      <td>116.473902,39.997834</td>\n",
       "      <td>望京西园4区410号综合楼1层</td>\n",
       "      <td>050301</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>B000A7BM4H</td>\n",
       "      <td>肯德基(花家地店)</td>\n",
       "      <td>北京市朝阳区</td>\n",
       "      <td>110105</td>\n",
       "      <td>116.469221,39.985569</td>\n",
       "      <td>花家地小区1号商业楼</td>\n",
       "      <td>050301</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>B000A7C99U</td>\n",
       "      <td>肯德基(酒仙桥店)</td>\n",
       "      <td>北京市朝阳区</td>\n",
       "      <td>110105</td>\n",
       "      <td>116.490345,39.975456</td>\n",
       "      <td>酒仙桥路12号</td>\n",
       "      <td>050301</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>B000A7FVJQ</td>\n",
       "      <td>肯德基(中福百货店)</td>\n",
       "      <td>北京市朝阳区</td>\n",
       "      <td>110105</td>\n",
       "      <td>116.463368,40.000511</td>\n",
       "      <td>望京南湖东园201号楼1层</td>\n",
       "      <td>050301</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>B0FFHPAN04</td>\n",
       "      <td>肯德基(望京西路店)</td>\n",
       "      <td>北京市朝阳区</td>\n",
       "      <td>110105</td>\n",
       "      <td>116.456811,39.994757</td>\n",
       "      <td>望京西路41号梦秀欢乐广场1层</td>\n",
       "      <td>050301</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>B000A80GPM</td>\n",
       "      <td>肯德基(酒仙桥二店)</td>\n",
       "      <td>北京市朝阳区</td>\n",
       "      <td>110105</td>\n",
       "      <td>116.495329,39.961923</td>\n",
       "      <td>酒仙桥路39号京客隆购物广场地下一层</td>\n",
       "      <td>050301</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>B000A9P8KT</td>\n",
       "      <td>肯德基(太阳宫凯德mall店)</td>\n",
       "      <td>北京市朝阳区</td>\n",
       "      <td>110105</td>\n",
       "      <td>116.448473,39.971184</td>\n",
       "      <td>太阳宫中路12号1层01-13A-14-15B</td>\n",
       "      <td>050301</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>B000A80HAN</td>\n",
       "      <td>肯德基(霄云路店)</td>\n",
       "      <td>北京市朝阳区</td>\n",
       "      <td>110105</td>\n",
       "      <td>116.464737,39.959245</td>\n",
       "      <td>霄云路27号中国庆安大厦1层</td>\n",
       "      <td>050301</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>B0FFF3DEDV</td>\n",
       "      <td>肯德基(三元桥东店)</td>\n",
       "      <td>北京市朝阳区</td>\n",
       "      <td>110105</td>\n",
       "      <td>116.456296,39.962578</td>\n",
       "      <td>曙光西里甲5号院24号楼凤凰汇购物中心B1层104号</td>\n",
       "      <td>050301</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           id             name district  adcode              location  \\\n",
       "0          []              肯德基       []      []                    []   \n",
       "1  B0FFKEPXS2        肯德基(望京西店)   北京市朝阳区  110105  116.473902,39.997834   \n",
       "2  B000A7BM4H        肯德基(花家地店)   北京市朝阳区  110105  116.469221,39.985569   \n",
       "3  B000A7C99U        肯德基(酒仙桥店)   北京市朝阳区  110105  116.490345,39.975456   \n",
       "4  B000A7FVJQ       肯德基(中福百货店)   北京市朝阳区  110105  116.463368,40.000511   \n",
       "5  B0FFHPAN04       肯德基(望京西路店)   北京市朝阳区  110105  116.456811,39.994757   \n",
       "6  B000A80GPM       肯德基(酒仙桥二店)   北京市朝阳区  110105  116.495329,39.961923   \n",
       "7  B000A9P8KT  肯德基(太阳宫凯德mall店)   北京市朝阳区  110105  116.448473,39.971184   \n",
       "8  B000A80HAN        肯德基(霄云路店)   北京市朝阳区  110105  116.464737,39.959245   \n",
       "9  B0FFF3DEDV       肯德基(三元桥东店)   北京市朝阳区  110105  116.456296,39.962578   \n",
       "\n",
       "                      address typecode city  \n",
       "0                          []       []   []  \n",
       "1             望京西园4区410号综合楼1层   050301   []  \n",
       "2                  花家地小区1号商业楼   050301   []  \n",
       "3                     酒仙桥路12号   050301   []  \n",
       "4               望京南湖东园201号楼1层   050301   []  \n",
       "5             望京西路41号梦秀欢乐广场1层   050301   []  \n",
       "6          酒仙桥路39号京客隆购物广场地下一层   050301   []  \n",
       "7     太阳宫中路12号1层01-13A-14-15B   050301   []  \n",
       "8              霄云路27号中国庆安大厦1层   050301   []  \n",
       "9  曙光西里甲5号院24号楼凤凰汇购物中心B1层104号   050301   []  "
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ts(my_key,'肯德基','050301','116.481488,39.990464','北京')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 交通态势"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "交通态势是一类简单的HTTP接口，提供根据用户输入的内容能够返回希望查询的交通态势情况。\n",
    "\n",
    "URL\n",
    "\n",
    "https://restapi.amap.com/v3/traffic/status/rectangle?parameters\n",
    "    \n",
    "* 请求参数：key(必填)rectangle\n",
    "\n",
    "* 选填参数：extensions  level\n",
    "\n",
    "***思考***\n",
    "* 最好的路线预判"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "def traffic(key,rectangle,level=None,extensions=None,sig=None,output=None,callback=None):\n",
    "    \"\"\"获取高德API地理编码\n",
    "    注释： key是指高德API密钥，请去注册\n",
    "        level:道路等级\n",
    "         rectangle代表此为矩形区域查询\n",
    "    \"\"\"\n",
    "    url = \"https://restapi.amap.com/v3/traffic/status/rectangle?parameters\"\n",
    "    parameters = {\n",
    "        \"key\":key,\n",
    "        \"level\":level,\n",
    "        \"extensions\":extensions,\n",
    "        \"rectangle\":rectangle,\n",
    "        \"sig\":sig,\n",
    "        \"callback\":callback,\n",
    "        \"output\":json\n",
    "    }\n",
    "    \n",
    "    response  = requests.get(url,params=parameters)\n",
    "    a = response.json()\n",
    "    return a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'info': 'INSUFFICIENT_PRIVILEGES',\n",
       " 'infocode': '10012',\n",
       " 'status': '0',\n",
       " 'sec_code_debug': 'd41d8cd98f00b204e9800998ecf8427e',\n",
       " 'key': '12f80238641864b66003f76e69819ee4',\n",
       " 'sec_code': 'd41d8cd98f00b204e9800998ecf8427e'}"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "traffic(my_key,'116.351147,39.966309;116.357134,39.968727')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## infocode:10012  该功能已经不向新用户开放"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 模块调用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "from geo import geo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function geo in module geo:\n",
      "\n",
      "geo(key, address, city=None, batch=None, sig=None, output=None, callback=None) -> str\n",
      "    获取高德API的地理编码\n",
      "    注释：key是指高德API的秘钥，请先去注册\n",
      "          填入address地理位置获得精确经纬度\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(geo)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'116.397477,39.908692'"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "geo(my_key,\"北京市天安门\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "284.436px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
